<?php
namespace app\appoint\model;
use app\BaseModel;
use think\facade\Db;



class AdminRecord extends BaseModel
{
    //定义表名
    protected $name = 'lb_appoint_record';
    protected  $append = [
        'sever_time_text',
    ];
    /**
     * @param $value
     * @return string
     * 转换状态
     */
    public function getStatusAttr($value){
        switch ($value) {
            case 1:
                $list = '未服务';
                break;
            case 2:
                $list = '已完成';
                break;
            case 3:
                $list = '已过期';
                break;
            default :
                $list = '已取消';
                break;
        }
        return $list;
    }
    /**
     * @param $value
     * @param $data
     * @return mixed
     * 服务时间
     */
    public function getSeverTimeTextAttr($value,$data){
        $time =  date('Y-m-d H:i', $data['start_time']) . '-' . date('H:i', $data['end_time']);
        return $time;
    }

    /**
     * @param $value
     * @return false|string
     * 转换时间
     */
    public function getCreateTimeAttr($value){
        return date('Y-m-d H:i:s',$value);
    }
    /**
     * @param $dis
     * @return array
     * @throws \think\exception\DbException
     * 预记录列表
     */
    public function recordList($dis,$page=10){
        $data = $this
            ->alias('a')
            ->leftJoin('lb_appoint_project b','a.project_id=b.id')
            ->where($dis)
            ->field('a.*,b.title as project_title,b.cover')
            ->group('a.id')
            ->order('a.id desc')
            ->paginate($page)
            ->toArray();
        $data['data'] = transImagesOne($data['data'],['cover']);
        return $data;
    }




}